package com.icinfo.cloud.provider.punish.strategy.document;

import com.icinfo.cloud.provider.punish.document.annotations.DocumentParamConvert;
import com.icinfo.cloud.provider.punish.document.dto.PrintDocumentBuildDto;
import com.icinfo.cloud.provider.punish.print.vo.ImageContentVo;
import com.icinfo.cloud.provider.punish.print.vo.PrintContentVo;
import com.icinfo.cloud.provider.punish.print.vo.PrintDocumentVo;
import com.icinfo.cloud.provider.punish.print.vo.TitleOrContentVo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.*;

/**
 * 公安简易处罚决定书
 *
 * @author Junfeng.Chen
 * @date 2024/1/15 8:49
 **/
@Data
@Slf4j
public class GajycxcfjdsDocumentParam implements BaseDocumentParam {
    /**
     * 单位名称
     */
    @DocumentParamConvert(narrow = "orgStandardName", standard = "orgStandardName")
    private String orgStandardName;

    /**
     * 文书号
     */
    @DocumentParamConvert(narrow = "documentNumber", standard = "documentNumber")
    private String documentNumber;

    /**
     * 当事人联系方式
     */
    @DocumentParamConvert(narrow = "mobile", standard = "mobile")
    private String mobile;

    /**
     * 当事人名称
     */
    @DocumentParamConvert(narrow = "partyName", standard = "partyName")
    private String partyName;

    /**
     * 交通方式
     */
    @DocumentParamConvert(narrow = "trafficWay", standard = "trafficWay")
    private String trafficWay;

    /**
     * 机动车驾驶证号
     */
    @DocumentParamConvert(narrow = "licenseNumber", standard = "licenseNumber")
    private String licenseNumber;

    /**
     * 机动车驾驶证档案编号
     */
    @DocumentParamConvert(narrow = "licenseFileNumber", standard = "licenseFileNumber")
    private String licenseFileNumber;

    /**
     * 准驾车型：
     */
    @DocumentParamConvert(narrow = "allowCarType", standard = "allowCarType")
    private String allowCarType;

    /**
     * 身份证明名称
     */
    @DocumentParamConvert(narrow = "sfzmc", standard = "sfzmc")
    private String sfzmc;

    /**
     * certNo证件号码
     */
    @DocumentParamConvert(narrow = "certNo", standard = "certNo")
    private String certNo;

    /**
     * 机动车号牌号码
     */
    @DocumentParamConvert(narrow = "carPlateNumber", standard = "carPlateNumber")
    private String carPlateNumber;

    /**
     * 车辆类型
     */
    @DocumentParamConvert(narrow = "carType", standard = "carType")
    private String carType;

    /**
     * 发证机关
     */
    @DocumentParamConvert(narrow = "licenceDepartment", standard = "licenceDepartment")
    private String licenceDepartment;

    /**
     * 违法日期
     */
    @DocumentParamConvert(narrow = "wfrq", standard = "wfrq")
    private String wfrq;

    /**
     * 违法地点
     */
    @DocumentParamConvert(narrow = "wfdd", standard = "wfdd")
    private String wfdd;

    /**
     * 违法行为
     */
    @DocumentParamConvert(narrow = "wfxw", standard = "wfxw")
    private String wfxw;


    /**
     * 违法代码
     */
    @DocumentParamConvert(narrow = "wfdm", standard = "wfdm")
    private String wfdm;

    /**
     * 违则
     */
    @DocumentParamConvert(narrow = "illegalBasis", standard = "illegalBasis")
    private String illegalBasis;

    /**
     * 罚则
     */
    @DocumentParamConvert(narrow = "punishBasis", standard = "punishBasis")
    private String punishBasis;

    /**
     * 罚则
     */
    @DocumentParamConvert(narrow = "cfjd", standard = "cfjd")
    private String cfjd;

    /**
     * 复议机构
     */
    @DocumentParamConvert(narrow = "JYCXCFJDS_FYJG", standard = "JYCXCFJDS_FYJG")
    private String JYCXCFJDS_FYJG;

    /**
     * 起诉法院
     */
    @DocumentParamConvert(narrow = "JYCXCFJDS_QSFY", standard = "JYCXCFJDS_QSFY")
    private String JYCXCFJDS_QSFY;


    /**
     * 部门签章base64
     */
    @DocumentParamConvert(narrow = "signFingerprint", standard = "signFingerprint")
    private String signFingerprint;

    /**
     * 被处罚人签名
     */
    @DocumentParamConvert(narrow = "signFingerprintPic", standard = "signFingerprintPic")
    private String signFingerprintPic;

    /**
     * 签章时间
     */
    @DocumentParamConvert(narrow = "signFingerprintDate", standard = "signFingerprintDate")
    private String signFingerprintDate;

    /**
     * 执法人员-主办案人
     */
    @DocumentParamConvert(narrow = "mainHandleSignPic", standard = "mainHandleSignPic")
    private String mainHandleSignPic;

    /**
     * 执法人员-协办人
     */
    @DocumentParamConvert(narrow = "assistHandleSignPic", standard = "assistHandleSignPic")
    private String assistHandleSignPic;

    /**
     * 备注
     */
    @DocumentParamConvert(narrow = "caseRemark", standard = "caseRemark")
    private String caseRemark;

    /**
     * 记分依据
     */
    @DocumentParamConvert(narrow = "scoringBasis", standard = "scoringBasis")
    private String scoringBasis;

    /**
     * 记分
     */
    @DocumentParamConvert(narrow = "jf", standard = "jf")
    private String jf;


    @Override
    public PrintDocumentVo assemblyPrintContent(PrintDocumentBuildDto dto) {
        PrintContentVo textContent = new PrintContentVo();
        textContent.setTitle(assemblyTitle());
        textContent.setPartyInfo(assemblyPartyInfo());
        textContent.setBodyContent(assemblyBodyContent());
        textContent.setImageInfo(assemblyImageInfo(dto));
        return new PrintDocumentVo(null, textContent);
    }

    /**
     * 组装图片板块
     *
     * @param dto
     * @return
     */
    private List<ImageContentVo> assemblyImageInfo(PrintDocumentBuildDto dto) {
        List<ImageContentVo> imageInfo = new LinkedList<>();
        //部门签章
        imageInfo.add(new ImageContentVo()
                .setDescription("")
                //url转base64存入
                .setImageBase64(Collections.singletonList(signFingerprint))
                .setImagePosition(1).setComment(Collections.emptyList()).initNormalStyle().setImagePosition(3));
        //签章日期
        imageInfo.add(new ImageContentVo()
                .setDescription("")
                .setImageBase64(Collections.singletonList(""))
                .setImagePosition(1)
                .setComment(Collections.singletonList(Optional.ofNullable(signFingerprintDate).orElse("")))
                .initNormalStyle()
                .setTextPosition(3));
        //执法人员
        imageInfo.add(new ImageContentVo()
                .setDescription("执法人员：")
                .setImageBase64(Arrays.asList(convertImageUrlToBase64(mainHandleSignPic), convertImageUrlToBase64(assistHandleSignPic)))
                .setImagePosition(1).setComment(Collections.emptyList()).initNormalStyle());
        //被处罚人签名或者捺指印：
        imageInfo.add(new ImageContentVo()
                .setDescription("被处罚人签名或者捺指印：")
                .setImageBase64(Collections.singletonList(Optional.ofNullable(signFingerprintPic).orElse("")))
                .setImagePosition(1).setComment(Collections.emptyList()).initNormalStyle());
        //被处罚人签名日期
        imageInfo.add(new ImageContentVo()
                .setDescription("")
                .setImageBase64(Collections.singletonList(""))
                .setImagePosition(1)
                .setComment(Collections.singletonList(Optional.ofNullable(signFingerprintDate).orElse("")))
                .initNormalStyle()
                .setTextPosition(3));
        //备注
        imageInfo.add(new ImageContentVo()
                .setDescription("备注：" + Optional.ofNullable(caseRemark).orElse(""))
                .setImageBase64(Collections.singletonList(""))
                .setImagePosition(1)
                .setComment(Collections.emptyList())
                .initNormalStyle());
        //文本
        imageInfo.add(new ImageContentVo()
                .setDescription("一式三份，一份由被处罚人交银行，一份送达被处罚人，一份留存")
                .setImageBase64(Collections.singletonList(""))
                .setImagePosition(1)
                .setComment(Collections.emptyList())
                .initNormalStyle());
        imageInfo.add(new ImageContentVo()
                .setDescription("处理地：重庆市")
                .setImageBase64(Collections.singletonList(""))
                .setImagePosition(1)
                .setComment(Collections.emptyList())
                .initNormalStyle());
        //记分等
        imageInfo.add(new ImageContentVo()
                .setDescription("依据" + Optional.ofNullable(scoringBasis).orElse("/") + "，记" + Optional.ofNullable(jf).orElse("/") + "分")
                .setImageBase64(Collections.singletonList(""))
                .setImagePosition(1)
                .setComment(Collections.emptyList())
                .initNormalStyle());
        return imageInfo;
    }

    /**
     * 组装内容
     *
     * @return
     */
    private List<TitleOrContentVo> assemblyBodyContent() {
        List<TitleOrContentVo> bodyContent = new LinkedList<>();
        String content1 = "    被处罚人于" + Optional.ofNullable(wfrq).orElse("") +
                "，在" + Optional.ofNullable(wfdd).orElse("") + "实施" + Optional.ofNullable(wfxw).orElse("") + "违法行为"
                + Optional.ofNullable(wfdm).orElse("");
        String content2 = "违反了：";
        String content3 = Optional.ofNullable(illegalBasis).orElse("") + "规定。";
        String content4 = "依据" + Optional.ofNullable(punishBasis).orElse("") + "，决定处以：" + Optional.ofNullable(cfjd).orElse("") + "。";
        String content5 = "持本决定书在15日内到工商银行、农业银行、交通银行、邮政储蓄银行、建设银行、重庆农村商业银行缴纳罚款。逾期不缴纳的，每日按罚款数额的3％加处罚款，加处罚款的数额不超过罚款本数。";
        String content6 = "    对本行政处罚决定不服的，可以在收到《行政处罚决定书》之日起六十日内向" + Optional.ofNullable(JYCXCFJDS_FYJG).orElse("")
                + "申请行政复议，对行政复议决定不服的，可以再依法向人民法院提起行政诉讼。行政复议申请既可以向行政复议机关提交，也可以通过本机关提交。";
        String content7 = "    行政复议期间，本决定不停止执行，但法律另有规定的除外。当事人逾期不申请行政复议又不履行的，本机关将依法强制执行，或者申请人民法院强制执行。";
        String content8 = "    处罚前已口头告知违法行为人拟作出处罚的事实、理由和依据，并告知违法行为人依法享有陈述权和申辩权。";
        bodyContent.add(new TitleOrContentVo(content1).initNormalStyle());
        bodyContent.add(new TitleOrContentVo(content2).initNormalStyle());
        bodyContent.add(new TitleOrContentVo(content3).initNormalStyle());
        bodyContent.add(new TitleOrContentVo(content4).initNormalStyle());
        bodyContent.add(new TitleOrContentVo(content5).initNormalStyle());
        bodyContent.add(new TitleOrContentVo(content6).initNormalStyle());
        bodyContent.add(new TitleOrContentVo(content7).initNormalStyle());
        bodyContent.add(new TitleOrContentVo(content8).initNormalStyle());
        return bodyContent;
    }

    /**
     * 组装当事人信息
     *
     * @return
     */
    private List<TitleOrContentVo> assemblyPartyInfo() {
        List<TitleOrContentVo> partyInfo = new LinkedList<>();
        //当事人
        partyInfo.add(new TitleOrContentVo("被处罚人：" + Optional.ofNullable(partyName).orElse("") + " "
                + "联系方式：" + Optional.ofNullable(mobile).orElse("")).initNormalStyle());
        partyInfo.add(new TitleOrContentVo("交通方式：" + Optional.ofNullable(trafficWay).orElse("")).initNormalStyle());
        partyInfo.add(new TitleOrContentVo("机动车驾驶证号：" + Optional.ofNullable(licenseNumber).orElse("")).initNormalStyle());
        partyInfo.add(new TitleOrContentVo("机动车驾驶证档案编号：" + Optional.ofNullable(licenseFileNumber).orElse("")).initNormalStyle());
        partyInfo.add(new TitleOrContentVo("准驾车型：" + Optional.ofNullable(allowCarType).orElse("")).initNormalStyle());
        partyInfo.add(new TitleOrContentVo("身份证明名称：" + Optional.ofNullable(sfzmc).orElse("")).initNormalStyle());
        partyInfo.add(new TitleOrContentVo("号码：" + Optional.ofNullable(certNo).orElse("")).initNormalStyle());
        partyInfo.add(new TitleOrContentVo("机动车号牌号码：" + Optional.ofNullable(carPlateNumber).orElse("")).initNormalStyle());
        partyInfo.add(new TitleOrContentVo("车辆类型：" + Optional.ofNullable(carType).orElse("")).initNormalStyle());
        partyInfo.add(new TitleOrContentVo("发证机关：" + Optional.ofNullable(licenceDepartment).orElse("")).initNormalStyle());
        return partyInfo;
    }

    /**
     * 组装头部信息
     *
     * @return
     */
    private List<TitleOrContentVo> assemblyTitle() {
        List<TitleOrContentVo> title = new LinkedList<>();
        title.add(new TitleOrContentVo(Optional.ofNullable(orgStandardName).orElse("")).initTitleStyle().setSize(2));
        title.add(new TitleOrContentVo("公安交通管理简易程序处罚决定书").initTitleStyle());
        title.add(new TitleOrContentVo("编号：" + Optional.ofNullable(documentNumber).orElse("")).initDocumentNumberStyle());
        return title;
    }
}
